package com.opgea.crm.web.form;

import java.util.ArrayList;
import java.util.List;

import com.opgea.crm.common.constant.ApplicationConstant;
import com.opgea.crm.domain.entities.Company;
import com.opgea.crm.domain.entities.Companyaddresses;
import com.opgea.crm.domain.entities.Companycompetitors;
import com.opgea.crm.domain.entities.Lead;
import com.opgea.crm.domain.entities.Leademails;
import com.opgea.crm.domain.entities.Leadphones;
import com.opgea.crm.domain.entities.Leadprofile;


public class CustomerForm {

	private String searchCriteria;
	private String criteriaValue;
	private String customerId;
	private String firstName;
	private String middleInitial;
	private String lastName;
	private String title;
	private String email;
	private String phone1;
	private String phone2;
	private String phone3;
	private String phone4;
	
	private String companyName;
	private String street1;
	private String street2;
	private String country;
	private String province;
	private String city;
	private String web;
	
	private String industryType;
	private long industryTypeId;
	
	private ApplicationConstant.LeadStatusQualifier customerStatusType;
	private long customerStatusTypeId;
	
	private String source;
	private long sourceId;
	
	private String category;
	private long categoryId;
	
	private String grade;
	private long gradeId;
	
	private String customerStage;
	private long customerStageId;
	
	private String action;
	private long actionId;
	
	private String closingProbability;
	private long closingProbabilityId;
	
	private String owner;
	private long ownerId;
	
	private String notes;
	private String companySize;
	private String annualRevenue;
	private String competitor1;
	private String competitor2;
	private String competitor3;
	


	public void setSearchCriteria(String searchCriteria) {
		this.searchCriteria = searchCriteria;
	}

	public String getSearchCriteria() {
		return searchCriteria;
	}

	public void setCriteriaValue(String criteriaValue) {
		this.criteriaValue = criteriaValue;
	}

	public String getCriteriaValue() {
		return criteriaValue;
	}

	public void setCustomerId(String customerId) {
		this.customerId = customerId;
	}
	public String getCustomerId() {
		return customerId;
	}
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	public String getMiddleInitial() {
		return middleInitial;
	}
	public void setMiddleInitial(String middleInitial) {
		this.middleInitial = middleInitial;
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getPhone1() {
		return phone1;
	}
	public void setPhone1(String phone1) {
		this.phone1 = phone1;
	}
	public String getPhone2() {
		return phone2;
	}
	public void setPhone2(String phone2) {
		this.phone2 = phone2;
	}
	public String getPhone3() {
		return phone3;
	}
	public void setPhone3(String phone3) {
		this.phone3 = phone3;
	}
	public String getPhone4() {
		return phone4;
	}
	public void setPhone4(String phone4) {
		this.phone4 = phone4;
	}
	public String getCompanyName() {
		return companyName;
	}
	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}
	public String getStreet1() {
		return street1;
	}
	public void setStreet1(String street1) {
		this.street1 = street1;
	}
	public String getStreet2() {
		return street2;
	}
	public void setStreet2(String street2) {
		this.street2 = street2;
	}
	public String getCountry() {
		return country;
	}
	public void setCountry(String country) {
		this.country = country;
	}
	public String getProvince() {
		return province;
	}
	public void setProvince(String province) {
		this.province = province;
	}
	public String getCity() {
		return city;
	}
	public void setCity(String city) {
		this.city = city;
	}
	public String getWeb() {
		return web;
	}
	public void setWeb(String web) {
		this.web = web;
	}
	
	

	

	public String getIndustryType() {
		return industryType;
	}

	public void setIndustryType(String industryType) {
		this.industryType = industryType;
	}

	public long getIndustryTypeId() {
		return industryTypeId;
	}

	public void setIndustryTypeId(long industryTypeId) {
		this.industryTypeId = industryTypeId;
	}

	public void setCustomerStatusType(ApplicationConstant.LeadStatusQualifier customerStatusType) {
		this.customerStatusType = customerStatusType;
	}

	public ApplicationConstant.LeadStatusQualifier getCustomerStatusType() {
		return customerStatusType;
	}

	public void setCustomerStatusTypeId(long customerStatusTypeId) {
		this.customerStatusTypeId = customerStatusTypeId;
	}

	public long getCustomerStatusTypeId() {
		return customerStatusTypeId;
	}

	public String getSource() {
		return source;
	}

	public void setSource(String source) {
		this.source = source;
	}

	public long getSourceId() {
		return sourceId;
	}

	public void setSourceId(long sourceId) {
		this.sourceId = sourceId;
	}

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public long getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(long categoryId) {
		this.categoryId = categoryId;
	}

	public String getGrade() {
		return grade;
	}

	public void setGrade(String grade) {
		this.grade = grade;
	}

	public long getGradeId() {
		return gradeId;
	}

	public void setGradeId(long gradeId) {
		this.gradeId = gradeId;
	}

	

	public String getCustomerStage() {
		return customerStage;
	}

	public void setCustomerStage(String customerStage) {
		this.customerStage = customerStage;
	}

	public long getCustomerStageId() {
		return customerStageId;
	}

	public void setCustomerStageId(long customerStageId) {
		this.customerStageId = customerStageId;
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	public long getActionId() {
		return actionId;
	}

	public void setActionId(long actionId) {
		this.actionId = actionId;
	}

	public String getClosingProbability() {
		return closingProbability;
	}

	public void setClosingProbability(String closingProbability) {
		this.closingProbability = closingProbability;
	}

	public long getClosingProbabilityId() {
		return closingProbabilityId;
	}

	public void setClosingProbabilityId(long closingProbabilityId) {
		this.closingProbabilityId = closingProbabilityId;
	}

	public String getOwner() {
		return owner;
	}

	public void setOwner(String owner) {
		this.owner = owner;
	}

	public long getOwnerId() {
		return ownerId;
	}

	public void setOwnerId(long ownerId) {
		this.ownerId = ownerId;
	}

	public String getNotes() {
		return notes;
	}
	public void setNotes(String notes) {
		this.notes = notes;
	}
	public String getCompanySize() {
		return companySize;
	}
	public void setCompanySize(String companySize) {
		this.companySize = companySize;
	}
	public String getAnnualRevenue() {
		return annualRevenue;
	}
	public void setAnnualRevenue(String annualRevenue) {
		this.annualRevenue = annualRevenue;
	}
	public String getCompetitor1() {
		return competitor1;
	}
	public void setCompetitor1(String competitor1) {
		this.competitor1 = competitor1;
	}
	public String getCompetitor2() {
		return competitor2;
	}
	public void setCompetitor2(String competitor2) {
		this.competitor2 = competitor2;
	}
	public String getCompetitor3() {
		return competitor3;
	}
	public void setCompetitor3(String competitor3) {
		this.competitor3 = competitor3;
	}
	
	public CustomerForm(){}
	
	public CustomerForm(Lead lead){
		Company company = lead.getCompany();
		List<Companyaddresses> addresses = new ArrayList<Companyaddresses>(company.getCompanyaddressesCollection());
		List<Leadphones> phones = new ArrayList<Leadphones>(lead.getLeadphonesCollection());
		List<Companycompetitors> competitors = new ArrayList<Companycompetitors>(company.getCompanycompetitorsCollection());
		
		Companyaddresses address1 = addresses.get(0);

		Leadphones phone1 = null;
		Leadphones phone2 = null;
		Leadphones phone3 = null;
		Leadphones phone4 = null;
		if(phones.size()>0){
			phone1 = phones.get(0);
			phone2 = phones.get(1);
			phone3 = phones.get(2);
			phone4 = phones.get(3);
		}
		
		Leademails email1 = lead.getLeademail();
		Leadprofile profile1 = lead.getLeadprofile();
		
		this.setCompanyName(company.getName());
		this.setStreet1(address1.getStreet1());
		this.setStreet2(address1.getStreet2());
		this.setCountry(address1.getCountry());
		this.setProvince(address1.getCity()); //province need to correct
		this.setCity(address1.getCity());
		this.setWeb(company.getWebsite());
		this.setCustomerStatusTypeId(this.getCustomerStatusTypeId());
		
		this.setCustomerId(String.valueOf(lead.getId()));
		this.setFirstName(lead.getFirstName());
		this.setMiddleInitial(lead.getMiddleInitial());
		this.setLastName(lead.getLastName());
		this.setTitle(lead.getTitle());
		this.setEmail(email1.getAddress());
		this.setPhone1(phone1.getPhoneNo());
		this.setPhone2(phone2.getPhoneNo());
		this.setPhone3(phone3.getPhoneNo());
		this.setPhone4(phone4.getPhoneNo());		
		
		if(company.getIndustryType() != null){
			this.setIndustryType(company.getIndustryType().getFieldValue());
			this.setIndustryTypeId(company.getIndustryType().getId());
		}
		
        if(profile1.getSource() != null){
        	System.out.println("Source Defination : "+profile1.getSource().getId()+" / "+profile1.getSource().getFieldValue());
        	this.setSource(profile1.getSource().getFieldValue());
        	this.setSourceId(profile1.getSource().getId());
        }
        if(profile1.getCategory() != null){
        	this.setCategory(profile1.getCategory().getFieldValue());
        	this.setCategoryId(profile1.getCategory().getId());
        }
        if(profile1.getGrade() != null){
        	this.setGrade(profile1.getGrade().getFieldValue());
        	this.setGradeId(profile1.getGrade().getId());
        }
        if(profile1.getStage() != null){
        	this.setCustomerStage(profile1.getStage().getFieldValue());
        	this.setCustomerStageId(profile1.getGrade().getId());
        }
        if(profile1.getAction() != null){
        	this.setAction(profile1.getAction().getFieldValue());
        	this.setActionId(profile1.getAction().getId());
        }
        if(profile1.getClosingProbability() != null){
        	this.setClosingProbability(profile1.getClosingProbability().getFieldValue());
        	this.setClosingProbabilityId(profile1.getClosingProbability().getId());
        }
        if(profile1.getEmployee() != null){
        	this.setOwner(profile1.getEmployee().getFirstName());
        	this.setOwnerId(profile1.getEmployee().getId());
        }
        String notes = new String(profile1.getNotes());
        this.setNotes(notes);
		this.setCustomerStatusType(ApplicationConstant.LeadStatusQualifier.values()[lead.getLeadStatus().ordinal()]);

		long companySize = 0;
		long annualRevenue = 0;
		if(company.getCompanySize() != null){
			companySize = company.getCompanySize();
		}
		if(company.getAnnualRevenue() != null){
			annualRevenue = company.getAnnualRevenue();
		}
		this.setCompanySize(String.valueOf(companySize));
		this.setAnnualRevenue(String.valueOf(annualRevenue));
		
		Companycompetitors comp1 = null;
		Companycompetitors comp2 = null;
		Companycompetitors comp3 = null;
		if(competitors.size()>0){
			comp1 = competitors.get(0);
			comp2 = competitors.get(1);
			comp3 = competitors.get(2);
		}
		
		this.setCompetitor1(comp1.getName());
		this.setCompetitor2(comp2.getName());
		this.setCompetitor3(comp3.getName());
	}

}
